<?php
require_once(dirname(__FILE__) . '/app.php');

$view = "reg";

if ( $_POST ) {
	$u = array();
	$u['family_name'] = strval($_POST['familyName']);
	$u['personal_name'] = strval($_POST['personalName']);
	$u['family_name_kana'] = strval($_POST['familyNameKana']);
	
	$u['email'] = strval($_POST['email']);
	$u['tel_no'] = strval($_POST['mobile']);
	
	$u['password'] = strval($_POST['password']);
	$u['sex'] = abs(intval($_POST['sex']));
	
	if ( ! Utility::ValidEmail($u['email'], true) ) {
		Session::Set('error', '有効なメールアドレスではありません！');
		redirect( WEB_ROOT . '/reg.php');
	}
	$user = Users::GetUserByEmail($u['email']);
	if ( $user ){
		Session::Set('error', 'メールアドレスはすでに使われています！');
	}else if($_POST['cmpassword']==$_POST['password'] && $_POST['password']){
		//Users::Create($u);
		$view = "reg_confirm";
	}else{
		Session::Set('error', 'ユーザ名はすでに使われています。');
	}
}
include template($view);

